﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DDNY.WebPortals.Common;
using KeywordsBasedMVCPortal.Models;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Web.Caching;
using DailyMotion.DataAccess;


namespace DailyMotion.Controllers
{
    public class ApplicationController : Controller
    {
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //ViewBag.MainFeedTypes = YoutubeHelper.GetMainYoutubeFeedTypes();
            ////ViewBag.Playlists = YoutubeHelper.GetAllPlaylists();
            //ViewBag.Recommended = YoutubeHelper.GetRecommendedVideos("");
            ViewBag.Categories = GetAllCategories();
            DMHelper.GetVideosByChannelId("music", 1, 20);
            //ViewBag.Robots = SEOHelper.Index;
            WebLink resLink = LinkManager.GetRandomResLink();
            Random rand = new Random();
            ViewBag.ResLink = string.Format("<a href='{0}'>{1}</a>", resLink.LinkUrl, resLink.Anchor);



        }

        DailyMotionPagedResult GetAllCategories()
        {
            DailyMotionPagedResult allChannels = null;
            string cacheKey = "AllChannels";
            if (HttpContext.Cache[cacheKey] != null)
            {
                allChannels = (DailyMotionPagedResult)HttpContext.Cache[cacheKey];
            }
            else
            {
                allChannels = DMHelper.GetMainChannels();                
                HttpContext.Cache.Add(cacheKey, allChannels, null, DateTime.Now.AddHours(2), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
            }
            return allChannels;
        }
    }
}
